package com.example.demo48httpslogin.config;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TomcatConfig {

    /**
     * 配置Tomcat连接器工厂
     *
     * 此方法创建并配置一个TomcatServletWebServerFactory实例，通过添加额外的Tomcat连接器来定制化Tomcat服务器配置
     * 主要目的是为了定制HTTP连接器，例如设置HTTP协议、端口等
     *
     * @return TomcatServletWebServerFactory的实例，用于配置Tomcat服务器
     */
    @Bean
    public TomcatServletWebServerFactory tomcatServletWebServerFactory(){
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addAdditionalTomcatConnectors(createTomcatConnector());
        return factory;
    }

    /**
     * 创建Tomcat连接器
     *
     * 该方法负责构建和配置Tomcat的HTTP连接器这个连接器定义了HTTP协议的通信细节，
     * 比如使用的协议类型和监听的端口号本方法中配置的连接器使用HTTP/1.1协议和NIO异步非阻塞模式，
     * 并监听8080端口
     *
     * @return Connector对象，代表配置好的Tomcat HTTP连接器
     */
    private Connector createTomcatConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        return connector;
    }




}
